package com.example.blogsystem.config;

import com.example.blogsystem.common.AppVar;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description: 自定义的拦截器
 * User: DELL
 * Date: 2023-09-08
 * Time: 23:14
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession(false);
        if (session == null || session.getAttribute(AppVar.USER_SESSION_KEY) == null) {
            response.sendRedirect("login.html");
            return false;
        }
        return true;
    }
}
